package dao

import (
	"gorm.io/driver/sqlite"
	"gorm.io/gorm"
	"log"
)

var DB *gorm.DB

func InitSqlite() {
	dbConfig := &gorm.Config{}
	dbUrl := "./mall.db"
	db, err := gorm.Open(sqlite.Open(dbUrl), dbConfig)
	if err != nil {
		log.Fatalf("open config db failed, err: %v", err)
	}

	DB = db

	// 自动生成表
	err = DB.AutoMigrate(&User{}, &Dept{})
	if err != nil {
		log.Fatalf("自动生成表, err: %v", err)
	}
}
